package com.java.admin.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//登录保护拦截器
public class LoginProtectInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object userInfo = request.getSession().getAttribute("userInfo");

        if(userInfo!=null){
            //有数据可以直接访问
            return true;
        }else{
            //重定向到登陆页面
            response.sendRedirect(request.getContextPath()+"/index.html");
            return false;
        }

    }
}
